#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
typedef struct LinkNode{
	char data;
	struct LinkNode *next;
}*LiStack;
void InitStack(LiStack *s){
	printf("初始化中....\n");
	//生成一个头结点
	*s = (LiStack) malloc(sizeof(struct LinkNode));
	if(*s == NULL){
		printf("malloc fail\n");
		exit(0);
	}
	printf("初始化成功！！\n");
	(*s)->next = NULL;
}
bool StackEmpty(LiStack S){
	if(S->next == NULL){ //如果头节点下一个节点为空，就可以说明这个栈为空栈
		return true;
	}
	else {
		return false;
	}
}
bool Push(LiStack S,char x){
	LiStack newNode = (LiStack) malloc(sizeof(struct LinkNode));
	newNode->data = x;
	//头插法
	newNode->next = S->next;
	S->next = newNode;
	return true;
}
bool Pop(LiStack S,char *x){
	if(StackEmpty(S)){
		return false;
	}
	LiStack temp = NULL;
	*x = S->next->data;
	//删除栈顶元素节点
	temp = S->next;
	S->next = temp->next;
	free(temp);
	return true;
}
bool BracketsMatch(LiStack S,char ch[]){
	char *c;
	for(int i=0;i<strlen(ch);i++){
		if(ch[i] == '(')//入栈
		{
			Push(S, ch[i]);
		}
		else if(ch[i] == ')'){
			//出来一个
			if(!Pop(S, c)){
				return false;
			}
		}
	}
	if(StackEmpty(S)){
		return true;
	}
	else {
		return false;
	}
}
bool GetTop(LiStack S,char *x){
	if(StackEmpty(S)){
		return false;
	}
	*x = S->next->data;
	return true;
}
int main(int argc, char *argv[]) {
	LiStack stack = NULL;
	InitStack(&stack);
	if(BracketsMatch(stack,"a=(123.12+212)+(b21+0.2123)+")){
		printf("mathed");
	}
	else {
		printf("unmathed");
	}
}